package son.hut.vn;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.Menu;

public class MainActivity extends ListActivity {
	private MyDataOpenHelper  dataOpenHelper;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		dataOpenHelper = new MyDataOpenHelper(this);
		
		dataOpenHelper.insertStudent("Mai Viet Anh", 123456);
		dataOpenHelper.insertStudent("Vu Thanh Hien", 123456);
		dataOpenHelper.insertStudent("Nguyen Huu Loc", 123456);
		dataOpenHelper.insertStudent("Nguyen Duy Duc", 123456);
		dataOpenHelper.insertStudent("Ha Van Thanh", 123456);
		dataOpenHelper.insertStudent("Nguyen Van Tung", 123456);
		dataOpenHelper.insertStudent("Nguyen Van Son", 123456);
		dataOpenHelper.insertStudent("Mai Viet Anh", 123456);
		
		
		Cursor mCursor = dataOpenHelper.selectStudents();
		SimpleCursorAdapter adapter = new SimpleCursorAdapter(
				this,
				R.layout.layoutitem,
				mCursor, 
				new String[]{"_id","Name","Phone"}, 
				new int[]{R.id.tvId, R.id.tvName, R.id.tvPhone});
		
		setListAdapter(adapter);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
